//
//  Stand ViewController.m
//  MZJ
//
//  Created by XDD on 16/6/25.
//  Copyright © 2016年 XDD. All rights reserved.
//

#import "StandViewController.h"
#import "News_DetailViewController.h"

@interface StandViewController ()<UIWebViewDelegate,UIScrollViewDelegate,ModelDelegate>

@property (nonatomic, strong) UIWebView *stand_Detail_webView;
@property (nonatomic, strong) ModelViewController *modelViewController;
@property (nonatomic, strong) JSNetWorkingModel *model;


@end

@implementation StandViewController
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBarHidden = YES;
    self.tabBarController.tabBar.hidden = YES;

}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.topBar.backgroundColor = [UIColor colorWithRed:253/255.0 green:179/255.0 blue:10/255.0 alpha:1];
    self.titleLabel.text = [DataModel object].rescue_Name_Str;
    self.view.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:245/255.0 alpha:1];
    [self.backButton setTitle:@"" forState:UIControlStateNormal];
    
    _stand_Detail_webView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 55, kWidth, kHeight - 55)];
    _stand_Detail_webView.delegate = self;
    _stand_Detail_webView.scrollView.delegate = self;
    [self.view addSubview:_stand_Detail_webView];
    
    if (!_modelViewController) {
        _modelViewController = [[ModelViewController alloc]init];
        [_modelViewController modelUrl_Http_Request:station_NewsList_model fileName:@"station_newsDetailModel.txt" webview:_stand_Detail_webView];
    }
    
    if (!_model) {
        _model = [[JSNetWorkingModel alloc]init];
    }
}

//点击返回键
- (void)clickedBackButton:(UIButton *)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
    self.tabBarController.tabBar.hidden = NO;
}

- (void)webViewDidFinishLoad:(UIWebView *)webView  {
    
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    
    [dic setObject:[DataModel object].rescue_List_Str forKey:@"cid"];
    
    __weak typeof (self)weakSelf = self;
    [_model setBlockWithReturnBlock:^(id returnValue) {

        [weakSelf.modelViewController JS_datarequestinitWebView:@"Home.station_news.V.create" andData:returnValue andwebView:weakSelf.stand_Detail_webView];
        //
    } WithErrorBlock:^(id errorCode) {
        
    }];
    
    [_model JS_HomeGetStand_listDetail:dic];
    [GiFHUD dismiss];

}

- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error {
    
}

- (void)webViewDidStartLoad:(UIWebView *)webView {
    [GiFHUD show];

}

- (BOOL)webView: (UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType {
    NSString *requestString = [[[request URL] absoluteString] stringByReplacingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
    
    NSLog(@"%@",requestString);
 
    if ([requestString rangeOfString:station_news_Detail].location != NSNotFound) {
        
        NSRange range = [requestString rangeOfString:@"arid"];
        NSString *str = [requestString substringFromIndex:range.location];
        [DataModel object].news_arid_Str = [str substringFromIndex:5];

        News_DetailViewController *news_DetailViewController = [[News_DetailViewController alloc]init];
        [self.navigationController pushViewController:news_DetailViewController animated:YES];
        //
        return NO;
    }
    
    return YES;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
